package com.easylinkin.linkappapi.openapi.service.impl;

import com.easylinkin.linkappapi.openapi.service.ApplicationCopyScreenService;
import com.easylinkin.linkappapi.security.entity.LinkappUser;
import com.easylinkin.linkappapi.security.service.LinkappUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @program: linkapp-group-cloud
 * @description: 首页配置大屏地址
 * @author: chenkaixuan
 * @create: 2021-09-07 14:43
 */
@Slf4j
@Order(2)
@Service
public class ApplicationCopyIndexScreenAddrServiceImpl implements ApplicationCopyScreenService {
    @Resource
    LinkappUserService linkappUserService;

    @Override
    public RestMessage copy(HashMap<String,String> map,HashMap<String,String> deviceMap,LinkappUser newLinkappUser, LinkappUser oldLinkappUser) {
        if (newLinkappUser == null || oldLinkappUser == null) {
            return RestBuilders.failureMessage().setMessage("用户为空");
        }
        RestMessage restMessage = RestBuilders.successBuilder().build();
//        if (map == null || map.size() <= 0) {
//            return restMessage;
//        }
        if(map == null || map.get(oldLinkappUser.getIndexConfigUrl()) == null){
            newLinkappUser.setIndexConfigCode(oldLinkappUser.getIndexConfigCode());
            newLinkappUser.setIndexConfigUrl(oldLinkappUser.getIndexConfigUrl());
        }else{
            newLinkappUser.setIndexConfigUrl(map.get(oldLinkappUser.getIndexConfigUrl()));
        }
        newLinkappUser.setIsShowScreen(oldLinkappUser.getIsShowScreen());
        linkappUserService.updateProfile(newLinkappUser);
        log.info("首页配置拷贝完成");
        return restMessage;
    }

    @Override
    public RestMessage copy(LinkappUser newLinkappUser, LinkappUser oldLinkappUser) {
        return null;
    }
}
